package com.itboye.textileexpes.presenter;

import java.util.List;
import java.util.Observer;

import android.util.Log;

import com.itboye.core.interfaces.ICompleteListener;
import com.itboye.textileexpes.beans.ReceiveAddressBean;
import com.itboye.textileexpes.beans.UserBean;
import com.itboye.textileexpes.interfaces.IReceiveAddress;
import com.itboye.textileexpes.interfaces.IUser;
import com.itboye.textileexpes.repository.ReceiveAddressRepository;
import com.itboye.textileexpes.repository.UserReposit;
import com.itboye.textileexpres.base.BasePresenter;
import com.itboye.textileexpres.base.ResultEntity;

public class ReceiveAddressPresenter extends BasePresenter implements
		IReceiveAddress<ReceiveAddressBean> {
	public static final String QuerySuccessEvent = MainPresenter.class
			.getName() + "_Query_success";
	public static final String QueryFailureEvent = MainPresenter.class
			.getName() + "_Query_failure";
	public static final String ADDSuccessEvent = MainPresenter.class.getName()
			+ "_ADD_success";
	public static final String ADDFailureEvent = MainPresenter.class.getName()
			+ "_ADD_failure";
	public static final String DeleteSuccessEvent = MainPresenter.class
			.getName() + "_Delete_success";
	public static final String DeleteFailureEvent = MainPresenter.class
			.getName() + "_Delete_failure";
	public static final String UpdateSuccessEvent = MainPresenter.class
			.getName() + "_Update_success";
	public static final String UpdateFailureEvent = MainPresenter.class
			.getName() + "_Update_failure";
	public static final String DefaultSuccessEvent = MainPresenter.class
			.getName() + "_Default_success";
	public static final String DefaultFailureEvent = MainPresenter.class
			.getName() + "_Default_failure";

	public ReceiveAddressPresenter(Observer observer) {
		super(observer);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void add(ReceiveAddressBean model) {
		// TODO Auto-generated method stub
		IReceiveAddress<ReceiveAddressBean> repo = new ReceiveAddressRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						Log.v("MainPresenter", "register success");
						result.setEventTag(Tag_Success);
						result.setEventType(ADDSuccessEvent);
						ReceiveAddressPresenter.this.setChanged();
						ReceiveAddressPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						Log.v("MainPresenter", "register failure");
						result.setEventTag(Tag_Error);
						result.setEventType(ADDFailureEvent);
						ReceiveAddressPresenter.this.setChanged();
						ReceiveAddressPresenter.this.notifyObservers(result);
					}
				});
		repo.add(model);
	}

	@Override
	public void delete(ReceiveAddressBean model) {
		// TODO Auto-generated method stub
		IReceiveAddress<ReceiveAddressBean> repo = new ReceiveAddressRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						Log.v("MainPresenter", "register success");
						result.setEventTag(Tag_Success);
						result.setEventType(DeleteSuccessEvent);
						ReceiveAddressPresenter.this.setChanged();
						ReceiveAddressPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						Log.v("MainPresenter", "register failure");
						result.setEventTag(Tag_Error);
						result.setEventType(DeleteFailureEvent);
						ReceiveAddressPresenter.this.setChanged();
						ReceiveAddressPresenter.this.notifyObservers(result);
					}
				});
		repo.delete(model);
	}

	@Override
	public void update(ReceiveAddressBean model) {
		// TODO Auto-generated method stub
		IReceiveAddress<ReceiveAddressBean> repo = new ReceiveAddressRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						Log.v("MainPresenter", "register success");
						result.setEventTag(Tag_Success);
						result.setEventType(UpdateSuccessEvent);
						ReceiveAddressPresenter.this.setChanged();
						ReceiveAddressPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						Log.v("MainPresenter", "register failure");
						result.setEventTag(Tag_Error);
						result.setEventType(UpdateFailureEvent);
						ReceiveAddressPresenter.this.setChanged();
						ReceiveAddressPresenter.this.notifyObservers(result);
					}
				});
		repo.update(model);
	}

	@Override
	public void getInfo(ReceiveAddressBean model) {
		// TODO Auto-generated method stub

	}

	@Override
	public List<ReceiveAddressBean> query(ReceiveAddressBean model) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void queryAddress(String uid) {
		// TODO Auto-generated method stub
		IReceiveAddress<ReceiveAddressBean> repo = new ReceiveAddressRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						Log.v("MainPresenter", "register success");
						result.setEventTag(Tag_Success);
						result.setEventType(QuerySuccessEvent);
						ReceiveAddressPresenter.this.setChanged();
						ReceiveAddressPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						Log.v("MainPresenter", "register failure");
						result.setEventTag(Tag_Error);
						result.setEventType(QueryFailureEvent);
						ReceiveAddressPresenter.this.setChanged();
						ReceiveAddressPresenter.this.notifyObservers(result);
					}
				});
		repo.queryAddress(uid);
	}

	@Override
	public void Default(String uid, String id) {
		// TODO Auto-generated method stub
		IReceiveAddress<ReceiveAddressBean> repo = new ReceiveAddressRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						Log.v("MainPresenter", "register success");
						result.setEventTag(Tag_Success);
						result.setEventType(DefaultSuccessEvent);
						ReceiveAddressPresenter.this.setChanged();
						ReceiveAddressPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						Log.v("MainPresenter", "register failure");
						result.setEventTag(Tag_Error);
						result.setEventType(DefaultFailureEvent);
						ReceiveAddressPresenter.this.setChanged();
						ReceiveAddressPresenter.this.notifyObservers(result);
					}
				});
		repo.Default(uid, id);
	}

}
